home *** CD-ROM | disk | FTP | other *** search
- // HackDragWindow.c
-
- #include "HackDragWindow.h"
- #include <Windows.h>
- #include <Menus.h>
- #include <TextUtils.h>
- #include <Files.h>
- #include <Traps.h>
- #include <A4Stuff.h>
- #include <SetupA4.h>
- #include <Resources.h>
- #include <ToolUtils.h>
- #include <Aliases.h>
-
- #include "FinderAE.h"
- #include "FileSystemStuff.h"
-
- #define waitingWindowsLimit 2
- #define waitingFilesLimit 10
-
-
- enum {
- fileIconID = -4000,
- folderIconID = -3997,
- hardDriveIconID = -3995,
- networkServerIconID = -3972,
- floppyIconID = -3998,
- cdRomIconID = -3987
- };
-
- enum {
- iconMapValue = 256,
- fileIconTempID = 260,
- folderIconTempID,
- hardDriveIconTempID
- };
-
- typedef struct WindowFileLink WindowFileLink;
- typedef WindowFileLink *WindowFileLinkPtr;
- typedef WindowFileLink **WindowFileLinkHandle;
-
- typedef pascal void (* DragWindowProcPtr) (WindowRef theWindow, Point startPt, const Rect *boundsRect);
- typedef pascal void (* CloseWindowProcPtr) (WindowRef theWindow);
- typedef pascal void (* SetWTitleProcPtr) (WindowRef theWindow, ConstStr255Param title);
- typedef pascal WindowRef (* NewWindowProcPtr) (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short procID, WindowRef behind, Boolean goAwayFlag, long refCon);
- typedef pascal void (* ShowWindowProcPtr) (WindowRef theWindow);
- typedef pascal short (* FindWindowProcPtr) (Point thePoint, WindowRef *theWindow);
-
- struct WindowFileLink
- {
- char nameLength;
- short volume;
- long parID;
- WindowPtr window;
- };
-
- typedef struct WindowFileLink WindowFileLink;
- typedef WindowFileLink *WindowFileLinkPtr;
- typedef WindowFileLink **WindowFileLinkHandle;
-
- struct DocPathData
- {
- UniversalProcPtr oldOpen;
- UniversalProcPtr oldClose; // not used anymore
-
- UniversalProcPtr oldDragWindow;
- UniversalProcPtr oldCloseWindow;
- UniversalProcPtr oldSetWTitle;
-
- UniversalProcPtr oldOpenRF;
- UniversalProcPtr oldHFSDispatch;
-
- UniversalProcPtr oldNewCWindow;
- UniversalProcPtr oldNewWindow;
- UniversalProcPtr oldShowWindow;
-
- UniversalProcPtr oldFindWindow;
-
- char howManyWaitingFiles;
- char howManyWaitingWindows;
- FSSpec waitingFiles[waitingFilesLimit];
- WindowPtr waitingWindows[waitingWindowsLimit];
- Str255 waitingWindowTitles[waitingWindowsLimit];
- WindowFileLinkHandle links;
- Boolean ignoringFiles;
- };
-
- typedef struct DocPathData DocPathData;
- typedef DocPathData *DocPathDataPtr;
- typedef DocPathData **DocPathDataHandle;
-
- DocPathDataHandle data;
-
- inline DocPathDataHandle HackData() { return data; }
- void DoHack( DocPathDataHandle theData,
- const WindowPtr window,
- const FSSpec *file,
- short titleTop,
- short titleLeft,
- short titleRight);
-
- Boolean RemoveHackWindow(DocPathDataHandle theData, WindowPtr window);
- void RememberDocWindow( DocPathDataHandle theData, const WindowPtr window,
- const FSSpec *file, char position);
- Boolean FindDocFile(DocPathDataHandle theData, ConstStr255Param windowTitle,
- FSSpec *file, char *position);
- Boolean IsDocumentFile( ConstStr255Param windowTitle, const FSSpec *file,
- char *position);
- void ConvertSpecToRefNum(DocPathDataHandle theData);
- Boolean CommandKey( void );
- Boolean OptionKey( void );
- void AppendItem(MenuHandle menuHandle, ConstStr255Param string, short type);
- void DoWindow(DocPathDataHandle theData, WindowPtr window, ConstStr255Param title);
- OSErr SetIconID( short oldID, short newID );
- void CompleteMenu(MenuHandle menuHandle);
- void MenuSelection(short selection, const FSSpec *file);
- long DoMenuSelect(MenuHandle menuHandle, Point position);
-
- #pragma parameter __D1 GetD1()
- extern pascal long GetD1()
- ONEWORDINLINE(0x4e71);
-
- pascal WindowPtr NewCWindowStub(void *wStorage,const Rect *boundsRect, ConstStr255Param title,
- Boolean visible, short procID, WindowRef behind, Boolean goAwayFlag, long refCon);
- pascal WindowPtr NewWindowStub(void *wStorage,const Rect *boundsRect, ConstStr255Param title,
- Boolean visible, short procID, WindowRef behind, Boolean goAwayFlag, long refCon);
-
- pascal void ShowWindowStub(WindowRef window);
-
- pascal short FindWindowStub(Point thePoint, WindowRef *theWindow);
-
- void DoNewFile(DocPathDataHandle theData, const FSSpec *file );
- void PutFileOnWaitingList(DocPathDataHandle theData, const FSSpec *file);
- void PutWindowOnWaitingList(DocPathDataHandle theData, const WindowPtr window, ConstStr255Param title);
- Boolean RemoveWaitingWindow(DocPathDataHandle theData, const WindowPtr window);
- Boolean SameFile(const FSSpec *file1, const FSSpec *file2);
-
- void OpenStub(void);
- void OpenRFStub(void);
- void HackOpen(HParmBlkPtr paramBlock);
-
- void GetWindowTitleRect(WindowPtr window, Rect *titleRect);
- Boolean FindHackWindow(DocPathDataHandle theData, WindowPtr window, FSSpec *file);
-
- void DragWindowStub();
- short HackDragWindow(WindowPtr, Point, Rect *);
-
- void CloseWindowStub();
- void CloseWindowHack(WindowPtr window);
-
- void SetWTitleStub();
- void SetWTitleHack(WindowPtr window, ConstStr255Param title);
-
- void HFSDispatchStub(void);
- void HFSDispatchHack(long selector, HParmBlkPtr pb);
-
-
- inline void AppendFile(MenuHandle menuHandle, ConstStr255Param name)
- {
- AppendItem(menuHandle, name, fileIconTempID);
- }
-
- inline void AppendFolder(MenuHandle menuHandle, ConstStr255Param name)
- {
- AppendItem(menuHandle, name, folderIconTempID);
- }
-
- inline void AppendVolume(MenuHandle menuHandle, ConstStr255Param name)
- {
- AppendItem( menuHandle, name, hardDriveIconTempID);
- }
-
- void main(void)
- {
- long oldA4;
- Handle initH = 0;
-
- oldA4 = SetCurrentA4();
- RememberA4();
-
- initH = Get1Resource('INIT', 333);
- if(initH)
- {
- HackInit();
- DetachResource(initH);
- }
-
- RestoreA4(oldA4);
- }
-
- void HackInit(void)
- {
- data = (DocPathDataHandle) NewHandleSys(sizeof(DocPathData));
- if(data)
- {
- (*data)->howManyWaitingFiles = 0;
- (*data)->howManyWaitingWindows = 0;
- (*data)->links = (WindowFileLinkHandle) NewHandleSys(0);
- (*data)->ignoringFiles = false;
-
- // (*data)->oldDragWindow = NGetTrapAddress (_DragWindow, ToolTrap);
- // NSetTrapAddress ((UniversalProcPtr)DragWindowStub, _DragWindow, ToolTrap);
-
- (*data)->oldCloseWindow = NGetTrapAddress (_CloseWindow, ToolTrap);
- NSetTrapAddress ((UniversalProcPtr)CloseWindowStub, _CloseWindow, ToolTrap);
-
- (*data)->oldSetWTitle = NGetTrapAddress (_SetWTitle, ToolTrap);
- NSetTrapAddress ((UniversalProcPtr)SetWTitleStub, _SetWTitle, ToolTrap);
-
- (*data)->oldOpen = NGetTrapAddress (_Open, OSTrap);
- NSetTrapAddress ((UniversalProcPtr)OpenStub, _Open, OSTrap);
-
- (*data)->oldOpenRF = NGetTrapAddress (_OpenRF, OSTrap);
- NSetTrapAddress ((UniversalProcPtr)OpenRFStub, _OpenRF, OSTrap);
-
- (*data)->oldHFSDispatch = NGetTrapAddress (_HFSDispatch, OSTrap);
- NSetTrapAddress ((UniversalProcPtr)HFSDispatchStub, _HFSDispatch, OSTrap);
-
- (*data)->oldNewCWindow = NGetTrapAddress (_NewCWindow, ToolTrap);
- NSetTrapAddress ((UniversalProcPtr)NewCWindowStub, _NewCWindow, ToolTrap);
-
- (*data)->oldNewWindow = NGetTrapAddress (_NewWindow, ToolTrap);
- NSetTrapAddress ((UniversalProcPtr)NewWindowStub, _NewWindow, ToolTrap);
-
- (*data)->oldFindWindow = NGetTrapAddress (_FindWindow, ToolTrap);
- NSetTrapAddress ((UniversalProcPtr)FindWindowStub, _FindWindow, ToolTrap);
-
- }
- }
-
-
- asm void DragWindowStub( void )
- {
-
- // Reserve space on the stack for real DragWindow address
- sub.l #4, SP
-
- // save registers
- movem.l A0-A5/D0-D7, -(SP)
-
- jsr SetUpA4
-
- // save real DragWindow address on the stack
- move.l data, A0
- move.l (A0), A0
- move.l 8(A0), 56(SP)
-
- // move HackDragWindow params on the stack
- move.l 64(SP),-(SP)
- move.l 72(SP),-(SP)
- move.l 80(SP),-(SP)
-
- jsr HackDragWindow
-
- TST.W D0
-
- // resotre stack pointer
- LEA 12(SP),SP
- movem.l (SP)+, A0-A5/D0-D7
-
- BNE.S *+4
-
- // forget about calling real DragWindow
- add.l #4, SP
-
- rts
- }
-
- short HackDragWindow(WindowPtr window, Point startPoint, Rect *boundsRect)
- {
- Rect titleRect;
- short titleStringLeft = 0, titleStringRight = 0;
- Boolean doDrag = true;
- DocPathDataHandle theData = HackData();
-
- GetWindowTitleRect(window, &titleRect);
-
- titleStringLeft = (titleRect.left +
- titleRect.right -
- ((WindowPeek) window)->titleWidth) / 2;
-
- titleStringRight = (titleRect.left +
- titleRect.right +
- ((WindowPeek) window)->titleWidth) / 2;
-
- if( CommandKey() &&
- (startPoint.h > titleStringLeft) &&
- (startPoint.h < titleStringRight) )
- {
- FSSpec file;
- if(FindHackWindow(theData, window, &file))
- {
- doDrag = false;
- DoHack(theData, window, &file, titleRect.top, titleStringLeft, titleStringRight);
- }
- }
- return doDrag;
- }
-
- void DoHack( DocPathDataHandle theData,
- const WindowPtr window,
- const FSSpec *file,
- short titleTop,
- short titleLeft,
- short titleRight)
- {
- MenuHandle menuHandle = NewMenu(55, "\p");
- if(menuHandle)
- {
- CInfoPBRec pb;
- Str255 curName;
- OSErr error = noErr;
- long selection;
- Point position;
-
- short volume = file->vRefNum;
- long directory = file->parID;
- short done = 0;
-
- AppendFile(menuHandle,file->name);
- pb.hFileInfo.ioCompletion = 0;
- pb.hFileInfo.ioNamePtr = curName;
-
- do
- {
- pb.hFileInfo.ioFDirIndex = -1;
- pb.hFileInfo.ioVRefNum = volume;
- pb.hFileInfo.ioDirID = directory;
-
- error = PBGetCatInfoSync( &pb );
- if(!error && (pb.hFileInfo.ioFlParID != directory))
- {
- directory = pb.hFileInfo.ioFlParID;
- AppendFolder(menuHandle, curName);
- }
- else
- done = 1;
- }
- while(!done);
-
- CompleteMenu(menuHandle);
-
- InsertMenu(menuHandle, -1);
- CalcMenuSize(menuHandle);
-
- position.v = titleTop;
- position.h = (titleRight + titleLeft - (*menuHandle)->menuWidth)/2;
-
- selection = DoMenuSelect(menuHandle, position);
-
- if(HiWord(selection))
- {
- selection = LoWord(selection);
- MenuSelection(selection, file);
- }
-
- DeleteMenu(55);
- DisposeMenu(menuHandle);
- }
- }
-
- long DoMenuSelect(MenuHandle menuHandle, Point position)
- {
- short savedResFile = CurResFile();
- long selection = 0;
-
- UseResFile(0);
- SetIconID( folderIconID, folderIconTempID );
- SetIconID( fileIconID, fileIconTempID );
- SetIconID( hardDriveIconID, hardDriveIconTempID );
-
- selection = PopUpMenuSelect( menuHandle, position.v, position.h, 0);
-
- SetIconID(folderIconTempID, folderIconID );
- SetIconID(fileIconTempID, fileIconID );
- SetIconID(hardDriveIconTempID, hardDriveIconID );
- UseResFile(savedResFile);
-
- return selection;
- }
-
- void MenuSelection(short selection, const FSSpec *file)
- {
- if(selection > 1)
- {
- Boolean bringFinderInFront = true;
- {
- FSSpec parent = *file, child;
- OSErr err = noErr;
- short count = 1;
- for(; !err && (count < selection); count++)
- {
- child = parent;
- err = GetParent(&child, &parent);
- }
- if(!err)
- {
- FinderOpen(&parent, bringFinderInFront);
- SelectItem(&child, bringFinderInFront);
- }
- }
- }
- }
-
-
- void AppendItem(MenuHandle menuHandle, ConstStr255Param string, short iconID)
- {
- short count = CountMItems(menuHandle) + 1;
- AppendMenu(menuHandle, "\pa");
-
- SetMenuItemText(menuHandle, count, string);
-
- SetItemIcon(menuHandle, count, iconID - iconMapValue);
- SetItemCmd(menuHandle, count, 0x1E);
- }
-
- void CompleteMenu(MenuHandle menuHandle)
- {
- SetItemIcon(menuHandle, CountMItems(menuHandle), hardDriveIconTempID - iconMapValue);
- }
-
- OSErr SetIconID( short oldID, short newID )
- {
- Handle iconResource = nil;
-
- SetResLoad(false);
- iconResource = GetResource('SICN', oldID);
- SetResLoad(true);
- if(iconResource)
- {
- Str255 name;
- short id;
- ResType type;
- GetResInfo(iconResource, &id, &type, name);
- if(!ResError())
- SetResInfo(iconResource, newID, name);
-
- }
- return ResError();
- }
-
- void GetWindowTitleRect(WindowPtr window, Rect *titleRect)
- {
- *titleRect = (**(((WindowPeek) window)->strucRgn)).rgnBBox;
- titleRect->top++;
- titleRect->bottom = (**(((WindowPeek) window)->contRgn)).rgnBBox.top - 1;
- }
-
-
- void HackOpen(HParmBlkPtr pb)
- {
- if(!(GetD1() & 0x0400) && pb->fileParam.ioNamePtr)
- {
- FSSpec file;
- OSErr err = MyFSMakeFSSpec ( pb->fileParam.ioVRefNum,
- pb->fileParam.ioDirID,
- pb->fileParam.ioNamePtr,
- &file);
- if(!err)
- {
- FInfo info;
- Boolean alias = false;
-
- #define kIsAlias 0x8000
- #define kHasBeenInited 0x100
- err = FSpGetFInfo(&file, &info);
- if(!err)
- {
- if (!(info.fdFlags & kIsAlias))
- {
- if((info.fdFlags & kHasBeenInited))
- DoNewFile(HackData(), &file);
- else
- {
- FSSpec parent;
- err = GetParent(&file, &parent);
- if(!err && !EqualString(parent.name, "\pRecent Documents", 0,0))
- DoNewFile(HackData(), &file);
- }
-
- }
- }
- }
- }
- }
-
- void DoNewFile(DocPathDataHandle theData, const FSSpec *file )
- {
- WindowPtr window = 0;
- char state = HGetState((Handle)theData);
- DocPathDataPtr dataPtr = *theData;
- short count;
- char position;
- HLock((Handle)theData);
-
- if(dataPtr->ignoringFiles)
- {
- if(!SameFile(file, &dataPtr->waitingFiles[0]))
- dataPtr->ignoringFiles = false;
- }
-
- if(!dataPtr->ignoringFiles)
- {
- for(count = dataPtr->howManyWaitingWindows - 1;(count >= 0) && !window; count--)
- {
- if(IsDocumentFile(dataPtr->waitingWindowTitles[count], file, &position))
- {
- window = dataPtr->waitingWindows[count];
- if(count < dataPtr->howManyWaitingWindows - 1)
- {
- BlockMoveData( &(dataPtr->waitingWindows[count + 1]),
- &(dataPtr->waitingWindows[count]),
- (dataPtr->howManyWaitingWindows - 1 - count) * sizeof(WindowPtr));
-
- BlockMoveData( &(dataPtr->waitingWindowTitles[count + 1]),
- &(dataPtr->waitingWindowTitles[count]),
- (dataPtr->howManyWaitingWindows - 1 - count) * 256);
- }
- dataPtr->howManyWaitingWindows--;
- dataPtr->ignoringFiles = true;
- dataPtr->waitingFiles[0] = *file;
- }
- }
- if(window)
- RememberDocWindow( theData, window, file, position);
- else
- PutFileOnWaitingList(theData, file);
- }
- HSetState((Handle) theData, state);
- }
-
- Boolean SameFile(const FSSpec *file1, const FSSpec *file2)
- {
- return (file1->vRefNum != file2->vRefNum ) ? false :
- (file1->parID != file2->parID ) ? false :
- EqualString (file1->name, file2->name, 0, 0);
- }
-
- void PutFileOnWaitingList(DocPathDataHandle theData, const FSSpec *file)
- {
- if((*theData)->howManyWaitingFiles == waitingFilesLimit)
- {
- BlockMoveData( &(*theData)->waitingFiles[1],
- &(*theData)->waitingFiles[0],
- (waitingFilesLimit - 1) * sizeof(FSSpec));
- (*theData)->howManyWaitingFiles--;
- }
- (*theData)->waitingFiles[(*theData)->howManyWaitingFiles++] = *file;
- }
-
- void PutWindowOnWaitingList(DocPathDataHandle theData, const WindowPtr window, ConstStr255Param title)
- {
- RemoveWaitingWindow(theData, window);
- if((*theData)->howManyWaitingWindows == waitingWindowsLimit)
- {
- BlockMoveData( &(*theData)->waitingWindows[1],
- &(*theData)->waitingWindows[0],
- (waitingWindowsLimit - 1) * sizeof(WindowPtr));
-
- BlockMoveData( &(*theData)->waitingWindowTitles[1],
- &(*theData)->waitingWindowTitles[0],
- (waitingWindowsLimit - 1) * 256);
- (*theData)->howManyWaitingWindows--;
- }
- BlockMoveData(title, &(*theData)->waitingWindowTitles[(*theData)->howManyWaitingWindows], title[0] + 1);
- (*theData)->waitingWindows[(*theData)->howManyWaitingWindows++] = window;
- }
-
- asm void OpenStub( void )
- {
-
- // Reserve space on the stack for real Open address
- sub.l #4, SP
-
- movem.l A1-A5/D0-D7, -(SP)
-
- move.l A0, -(SP)
-
- jsr SetUpA4
-
- move.l data, A0
- move.l (A0), A0
-
- move.l (A0), 56(SP)
-
- jsr HackOpen
-
- move.l (SP)+,A0
-
- movem.l (SP)+, A1-A5/D0-D7
-
- rts
- }
-
- asm void OpenRFStub( void )
- {
-
- // Reserve space on the stack for real Open address
- sub.l #4, SP
-
- movem.l A1-A5/D0-D7, -(SP)
-
- move.l A0, -(SP)
-
- jsr SetUpA4
-
- move.l data, A0
- move.l (A0), A0
-
- move.l 20(A0), 56(SP)
-
- jsr HackOpen
-
- move.l (SP)+,A0
-
- movem.l (SP)+, A1-A5/D0-D7
-
- rts
- }
-
- asm void HFSDispatchStub( void )
- {
-
- // Reserve space on the stack for real HFSDispatchStub address
- sub.l #4, SP
-
- movem.l A1-A5/D1-D7, -(SP)
-
- move.l A0, -(SP)
- move.l D0, -(SP)
-
- jsr SetUpA4
-
- move.l data, A0
- move.l (A0), A0
-
- move.l 24(A0), 56(SP)
-
- jsr HFSDispatchHack
-
- move.l (SP)+,D0
- move.l (SP)+,A0
-
- movem.l (SP)+, A1-A5/D1-D7
-
- rts
- }
-
- void HFSDispatchHack(long selector, HParmBlkPtr pb)
- {
- if(selector == 0x1A)
- HackOpen(pb);
- }
-
- asm void SetWTitleStub()
- {
- // Reserve space on the stack for real SetWTitle address
- sub.l #4, SP
-
- // save registers
- movem.l A0-A5/D0-D7, -(SP)
-
- jsr SetUpA4
-
- move.l data, A0
- move.l (A0), A0
- move.l 16(A0), 56(SP)
-
- // move SetWTitleHack params on the stack
- move.l 64(SP),-(SP)
- move.l 72(SP),-(SP)
-
- jsr SetWTitleHack
-
- // resotre stack pointer
- LEA 8(SP),SP
-
- // resotre registers
- movem.l (SP)+, A0-A5/D0-D7
-
- rts
- }
-
- void SetWTitleHack(WindowPtr window, ConstStr255Param title)
- {
- DocPathDataHandle theData = HackData();
- DoWindow(theData, window, title);
- }
-
- void DoWindow(DocPathDataHandle theData, WindowPtr window, ConstStr255Param title)
- {
- RemoveHackWindow(theData, window);
- RemoveWaitingWindow(theData, window);
- if(theData)
- {
- FSSpec file;
- char position;
- Boolean found = FindDocFile(theData,title, &file, &position);
- (*theData)->ignoringFiles = false;
-
- if(found)
- RememberDocWindow(theData, window, &file, position);
- else
- PutWindowOnWaitingList(theData, window, title);
- }
- }
-
- Boolean FindDocFile(DocPathDataHandle theData, ConstStr255Param windowTitle,
- FSSpec *file, char *position)
- {
- Boolean found = false;
- if(theData)
- {
- char state = HGetState((Handle)theData);
- DocPathDataPtr dataPtr = *theData;
- short count;
- HLock((Handle)theData);
-
- for(count = dataPtr->howManyWaitingFiles - 1;(count >= 0) && !found; count--)
- {
- if(IsDocumentFile(windowTitle, &dataPtr->waitingFiles[count], position))
- {
- found = true;
- *file = dataPtr->waitingFiles[count];
- if(count < dataPtr->howManyWaitingFiles - 1)
- BlockMoveData( &(dataPtr->waitingFiles[count + 1]),
- &(dataPtr->waitingFiles[count]),
- (dataPtr->howManyWaitingFiles - 1 - count) * sizeof(FSSpec));
- dataPtr->howManyWaitingFiles--;
- }
- }
- HSetState((Handle) theData, state);
- }
- return found;
- }
-
- inline Boolean IsDelimiter(unsigned char c)
- {
- return ((c >= '0' && c <= '9') ||
- (c >= 'A' && c <= 'Z') ||
- (c >= 'a' && c <= 'z')) ||
- (c==' ') ?
- false : true;
- }
-
- Boolean IsDocumentFile( ConstStr255Param windowTitle, const FSSpec *file, char *position)
- {
- unsigned char fnameLen = file->name[0];
- Boolean result = false;
- if(windowTitle[0] == fnameLen)
- {
- *position = 0;
- return EqualString (windowTitle, file->name, 0, 0);
- }
- else if((windowTitle[0] < fnameLen))
- return 0;
- else
- {
- unsigned char tempChar;
- unsigned char *midPtr;
- if(IsDelimiter(windowTitle[fnameLen + 1]))
- {
- *position = 1;
- tempChar = windowTitle[0];
- *((unsigned char *) windowTitle) = fnameLen;
- result = EqualString (windowTitle, file->name, 0, 0);
- *((unsigned char *) windowTitle) = tempChar;
- if(result)
- return 1;
- }
-
- midPtr = (StringPtr)windowTitle + windowTitle[0] - fnameLen;
- tempChar = *midPtr;
- if(IsDelimiter(tempChar))
- {
- *position = -1;
- *midPtr = fnameLen;
- result = EqualString (midPtr, file->name, 0, 0);
- *midPtr = tempChar;
- }
- }
- return result;
- }
-
- void RememberDocWindow( DocPathDataHandle theData, const WindowPtr window,
- const FSSpec *file, char position)
- {
- if(theData)
- {
- WindowFileLinkHandle LData = (*theData)->links;
- (*theData)->howManyWaitingFiles = 0;
- if(LData)
- {
- Size size = GetHandleSize((Handle) LData);
- char state = HGetState((Handle) LData);
- HUnlock((Handle) LData);
- SetHandleSize ((Handle) LData, size + sizeof(WindowFileLink));
- if(!MemError())
- {
- WindowFileLinkPtr dataPtr = *LData + size/sizeof(WindowFileLink);
- HLock((Handle) LData);
- dataPtr->window = window;
- dataPtr->volume = file->vRefNum;
- dataPtr->parID = file->parID;
- dataPtr->nameLength = position * file->name[0];
- }
- HSetState((Handle) LData, state);
- }
- }
- }
-
- Boolean FindHackWindow(DocPathDataHandle theData, WindowPtr window, FSSpec *file)
- {
- Boolean found = false;
- if(theData)
- {
- WindowFileLinkHandle LData = (*theData)->links;
- if(LData)
- {
- char state = HGetState((Handle) LData);
- Size size = GetHandleSize((Handle) LData);
- WindowFileLinkPtr dataPtr = *LData;
- WindowFileLinkPtr endPtr = dataPtr + size/sizeof(WindowFileLink);
-
- HLock((Handle) LData);
- for(; dataPtr < endPtr && !found; dataPtr++)
- {
- if(dataPtr->window == window)
- {
- Str255 windowTitle;
- found = true;
- file->vRefNum = dataPtr->volume;
- file->parID = dataPtr->parID;
- GetWTitle(window, windowTitle);
- if(dataPtr->nameLength == 0)
- BlockMoveData(windowTitle, file->name, windowTitle[0] + 1);
- else if(dataPtr->nameLength > 0)
- {
- file->name[0] = dataPtr->nameLength;
- BlockMoveData(windowTitle + 1, file->name + 1, dataPtr->nameLength);
- }
- else
- {
- file->name[0] = -dataPtr->nameLength;
- BlockMoveData( windowTitle + 1 + windowTitle[0] + dataPtr->nameLength,
- file->name + 1, -dataPtr->nameLength);
- }
- }
- }
- HSetState((Handle) LData, state);
- }
- }
- return found;
- }
-
-
- Boolean RemoveHackWindow(DocPathDataHandle theData, WindowPtr window)
- {
- Boolean found = false;
- if(theData)
- {
- WindowFileLinkHandle LData = (*theData)->links;
- if(LData)
- {
- char state = HGetState((Handle) LData);
- Size size = GetHandleSize((Handle) LData);
- WindowFileLinkPtr dataPtr = *LData;
- WindowFileLinkPtr endPtr = dataPtr + size/sizeof(WindowFileLink);
-
- HLock((Handle) LData);
- for(; dataPtr < endPtr && !found; dataPtr++)
- {
- if(dataPtr->window == window)
- {
- found = true;
- if((dataPtr + 1) < endPtr)
- {
- Ptr sourcePtr = (Ptr) (dataPtr + 1);
- long howMany = (Ptr) endPtr - sourcePtr;
- BlockMoveData(sourcePtr, dataPtr, howMany);
- }
- }
- }
- HSetState((Handle) LData, state);
- if(found)
- SetHandleSize((Handle) LData, size - sizeof(WindowFileLink));
- }
- }
- return found;
- }
-
- asm void CloseWindowStub()
- {
- // Reserve space on the stack for real CloseWindow address
- sub.l #4, SP
-
- // save registers
- movem.l A0-A5/D0-D7, -(SP)
-
- jsr SetUpA4
-
- // save real CloseWindow address on the stack
- move.l data, A0
- move.l (A0), A0
- move.l 12(A0), 56(SP)
-
- // move CloseWindow param on the stack
- move.l 64(SP),-(SP)
-
- jsr CloseWindowHack
-
- // resotre stack pointer
- LEA 4(SP),SP
-
- // resotre registers
- movem.l (SP)+, A0-A5/D0-D7
-
- rts
- }
-
- void CloseWindowHack(WindowPtr window)
- {
- DocPathDataHandle theData = HackData();
- (*theData)->howManyWaitingFiles = 0;
- if(!RemoveWaitingWindow(theData, window))
- RemoveHackWindow(theData, window);
- }
-
-
- Boolean RemoveWaitingWindow(DocPathDataHandle theData, const WindowPtr window)
- {
- Boolean found = false;
- if(theData)
- {
- char state = HGetState((Handle)theData);
- DocPathDataPtr dataPtr = *theData;
- short count;
- HLock((Handle)theData);
-
- for(count = dataPtr->howManyWaitingWindows - 1;(count >= 0) && !found; count--)
- {
- if(window == dataPtr->waitingWindows[count])
- {
- found = true;
- if(count < dataPtr->howManyWaitingWindows - 1)
- {
- BlockMoveData( &(dataPtr->waitingWindows[count + 1]),
- &(dataPtr->waitingWindows[count]),
- (dataPtr->howManyWaitingWindows - 1 - count) * sizeof(WindowPtr));
-
- BlockMoveData( &(dataPtr->waitingWindowTitles[count + 1]),
- &(dataPtr->waitingWindowTitles[count]),
- (dataPtr->howManyWaitingWindows - 1 - count) * 256);
- }
- dataPtr->howManyWaitingWindows--;
- }
- }
- HSetState((Handle) theData, state);
- }
- return found;
- }
-
- Boolean CommandKey( void )
- {
- KeyMap keys;
-
- GetKeys(keys);
- return (keys[1] & ( 1L << 15)) ? true : false;
- }
-
- Boolean OptionKey( void )
- {
- KeyMap keys;
-
- GetKeys(keys);
- return (keys[1] & ( 1L << 2)) ? true : false;
- }
-
- // evil, evil...
- pascal WindowPtr NewCWindowStub(void *wStorage, const Rect *boundsRect,
- ConstStr255Param title,Boolean visible,
- short procID, WindowRef behind,
- Boolean goAwayFlag, long refCon)
- {
- long oldA4 = SetUpA4();
- DocPathDataHandle theData = HackData();
-
- WindowPtr window = ((NewWindowProcPtr)((*data)->oldNewCWindow))
- (wStorage,boundsRect,
- title,visible,
- procID, behind,
- goAwayFlag, refCon);
- if(window)
- DoWindow(theData, window, title);
-
- RestoreA4(oldA4);
- return window;
- }
-
- pascal WindowRef NewWindowStub( void *wStorage, const Rect *boundsRect,
- ConstStr255Param title, Boolean visible,
- short theProc, WindowRef behind,
- Boolean goAwayFlag, long refCon)
- {
- long oldA4 = SetUpA4();
- DocPathDataHandle theData = HackData();
-
- WindowPtr window = ((NewWindowProcPtr)((*data)->oldNewWindow))
- (wStorage,boundsRect,
- title,visible,
- theProc, behind,
- goAwayFlag, refCon);
- if(window)
- DoWindow(theData, window, title);
-
- RestoreA4(oldA4);
- return window;
- }
-
- pascal short FindWindowStub( Point p, WindowRef *window)
- {
- long oldA4 = SetUpA4();
- DocPathDataHandle theData = HackData();
- Boolean didIt = false;
-
- short code = ((FindWindowProcPtr)((*data)->oldFindWindow))
- (p,window);
- if(window && (code == inDrag))
- {
- Rect boundsRect;
- didIt = !HackDragWindow(*window, p, &boundsRect);
- }
-
- if(didIt)
- {
- *window = 0;
- code = inDesk;
- }
-
- RestoreA4(oldA4);
- return code;
- }
-